﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Runtime.Serialization;
using System.Diagnostics;
using System.IO;


namespace ConvertExtensionT4
{
	class Run
	{
		
		static void Main(string[] args)
		{						
			var settings = ConvertExtensionT4.Properties.Settings.Default;
			runConvertTypesTemplate();
		}

		static void runConvertTypesTemplate()
		{
			var settings = ConvertExtensionT4.Properties.Settings.Default;
			Assembly srcA = Assembly.LoadFile(settings.SrcAssembly);
			Assembly destA = Assembly.LoadFile(settings.DestAssembly);			
			var template = new ConvertTypesTemplate
			{
				DestAssembly = destA,
				SrcAssembly = srcA, 
				Namespace = settings.destNamespace,
				//MustInheritFromSrcTypes = settings.MustInheritFromSrcTypeFullNames.Cast<string>().ToArray(),				
				ExcludeTypeFullNameSubstrings = settings.MustExcludeFullNameSubstrings.Cast<string>().ToArray(),				
				//NamespaceMappings = settings.destNamespace,				
			};
			string content = template.TransformText();
			foreach (string path in settings.destFullPaths.Cast<string>())
			{
				FileInfo f = new FileInfo(path);
				if (f.Exists)
					f.IsReadOnly = false;

				System.IO.File.WriteAllText(path, content);
			}
		}
	
	
        
	}
}
